(function() {


  //是否在MOCK 的配置项内
  function filterMock(url) {

    if (/(localhost|127.0.0.1|192.168)/.test(location.hostname)) {
      // return 'http://192.168.0.100:80' + url;
      // return 'http://127.0.0.1:80' + url;
      return url;
    } else {
      // 线上、测试
      return url;
    }
  }

  $.ajaxSetup({
    xhrFields: {
      withCredentials: true
    },

  });

  $._ajax = $.ajax;

  $.ajax = function() {
    var postData = arguments[0];
    var mockUrl;
    mockUrl = filterMock(postData.url);

    // $.ajax()支持类似$.ajax(url, settings)的调用方式，需要做下判断(since ver.1.5)。
    postData.url = mockUrl;

    return $._ajax(postData);
  }

  // $( document ).ajaxSuccess(function( event, xhr, settings ) {
  //     var data = xhr.responseJSON;
  //     if (data.message == '用户未登录') {
  //         location.href = '/login'
  //     }
  // });

})();
